package com.zzyl.mapper;

import com.zzyl.dto.ResourceDto;
import com.zzyl.entity.Resource;
import com.zzyl.vo.MenuVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ResourceMapper {

    int deleteByPrimaryKey(Long id);

    int insert(Resource record);

    int insertSelective(Resource record);

    Resource selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Resource record);

    int updateByPrimaryKey(Resource record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table sys_resource
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<Resource> list);

    List<Resource> selectList(Resource resource);

    @Select("select * from sys_resource where resource_no = #{resourceNo}")
    Resource selectByResourceNo(@Param("resourceNo") String parentResourceNo);

    @Select(("select * from sys_resource where id = #{id}"))
    Resource selectById(Long id);

    @Update("<script>" +
            "UPDATE sys_resource " +
            "SET data_state = 1 - data_state " +
            "WHERE resource_no IN " +
            "<foreach collection='resourceNos' item='no' open='(' separator=',' close=')'>" +
            "   #{no}" +
            "</foreach>" +
            " AND data_state IN (0,1)" +
            "</script>")
    void batchUpdateEnable(@Param("resourceNos") List<String> resourceNos);

    /**
     * 是否存在菜单子节点
     *
     * @param menuId 菜单ID
     * @return 结果
     */
    int hasChildByMenuId(@Param("menuId") String menuId);

    /**
     * 删除菜单管理信息
     *
     * @param menuId 菜单ID
     * @return 结果
     */
    int deleteMenuById(@Param("menuId") String menuId);

    @Update("UPDATE sys_resource SET parent_resource_no = #{parentNo}, update_time = #{updateTime} WHERE id = #{id}")
    int updateParentResourceNo(
            @Param("id") Long id,
            @Param("parentNo") String parentNo,
            @Param("updateTime") LocalDateTime updateTime
    );

    List<Resource> selectListByUserId(Long userId);

    List<MenuVo> findListByUserId(Long userId);

}